/*
 * ==============================================================================
 *  Name        : RegistrationListbox.cpp
 *  Part of     : Registration
 *  Interface   : 
 *  Description : 
 *  Version     : 
 *
 *  Copyright (c) 2005-2006 Nokia Corporation.
 *  This material, including documentation and any related 
 *  computer programs, is protected by copyright controlled by 
 *  Nokia Corporation.
 * ==============================================================================
 */

// INCLUDE FILES
#include "NormalSettingContainer.h"
#include "SHPlatform.h"
#include "QTextSetting.h"
#include "QInstance.h"
#include "cx_socket.h"
#include "EngineManager.h"
// ============================ MEMBER FUNCTIONS ==============================

void CDynamicSettingItem::CompleteConstructionL()
{
	CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();
	CArrayPtr<CAknEnumeratedText>* aEnumeratedTextArray = CAknEnumeratedTextPopupSettingItem::EnumeratedTextArray();
	aEnumeratedTextArray->ResetAndDestroy();
	CAknEnumeratedText* enumText = NULL;

	CArrayPtrFlat<CCIap> *pIapArray = new CArrayPtrFlat<CCIap>(8); 
	CArrayPtrFlat<CCIap>& array = *pIapArray;
	cx_iap_GetIapList(&array);

	for(TInt j = 0; j < array.Count(); j++)
	{
		HBufC* text = array.At(j)->iIapName.AllocL();
		TPtrC16 apn = array.At(j)->iIapApn;
		
		enumText = new (ELeave) CAknEnumeratedText(array.At(j)->iIapId,text);
		aEnumeratedTextArray->AppendL(enumText);
	}
	delete pIapArray;

	IndexFromValue(0); 
	HandleTextArrayUpdateL();
}
// ----------------------------------------------------------------------------
// CNormalSettingContainer::CreateSettingItemL()
// Updates descriptor array for list box
// ----------------------------------------------------------------------------
//
CAknSettingItem* CNormalSettingContainer::CreateSettingItemL(TInt aIdentifier)
	{
	CQTextSetting* setting = (CQTextSetting*)CQInstance::GetByUid(CQInstance::ETextSettingInstance);
	
	CAknSettingItem* settingItem = NULL;

	switch (aIdentifier)
		{
		case ESettingIAP:
			{
			//CCGPRSAgent* gprsAgent = CCGPRSAgent::InstanceL();
	#ifdef __WINS__	
			
	#else
			settingItem = new (ELeave) CDynamicSettingItem(aIdentifier,iIap);
	#endif
			}
			break;
//		case ESettingItemsPerPage:
//			settingItem = new (ELeave) CAknIntegerSettingItem (aIdentifier,
//					iNumber);
//			break;
		case ESettingVisibleItems:
			settingItem = new (ELeave) CAknBinaryPopupSettingItem(aIdentifier,
					iBool1);
			break;
//		case ESettingPlayAllMode:
//			settingItem = new (ELeave) CAknBinaryPopupSettingItem(aIdentifier,
//					iBool2);
//			break;
			//        case ERegistrationSettingName:
			//            settingItem = new ( ELeave ) CAknTextSettingItem( aIdentifier, 
			//                                                          iItemData->iName );
			//            break;
			//        
			//        case ERegistrationSettingEmail:
			//            settingItem = new ( ELeave ) CAknTextSettingItem( aIdentifier, 
			//                                                          iItemData->iEmail );
			//            break;
			//        
			//        case ERegistrationSettingPhone:
			//            settingItem = new ( ELeave ) CAknTextSettingItem( aIdentifier, 
			//                                                          iItemData->iPhone );
			//            break;
			//
			//        case ERegistrationSettingDate:
			//            settingItem = new ( ELeave ) CAknTimeOrDateSettingItem( 
			//                  aIdentifier, CAknTimeOrDateSettingItem::EDate, iItemData->iDate );
			//            break;
			//
			//        case ERegistrationSettingTime:
			//            settingItem = new ( ELeave ) CAknTimeOrDateSettingItem( 
			//                  aIdentifier, CAknTimeOrDateSettingItem::ETime, iItemData->iTime );
			//            break;
			//
			//        case ERegistrationSettingGender:
			//            settingItem = new ( ELeave ) CAknBinaryPopupSettingItem( 
			//                                                  aIdentifier, iItemData->iGender );
			//            break;
			//        
			//        case ERegistrationSettingLogin:
			//            settingItem = new ( ELeave ) CAknTextSettingItem( aIdentifier, 
			//                                                          iItemData->iLogin );
			//            break;
			//
			//        case ERegistrationSettingPassWord:
			//            settingItem = new ( ELeave ) CAknPasswordSettingItem( 
			//                     aIdentifier, CAknPasswordSettingItem::EAlpha, iItemData->iPw );
			//            break;
			//
			//        case ERegistrationSettingSlider:
			//            settingItem = new ( ELeave ) CAknSliderSettingItem( 
			//                                aIdentifier, iItemData->iSliderValue );
			//            break;
			//    
			//        case ERegistrationSettingAccept:
			//            settingItem = new ( ELeave ) CAknBinaryPopupSettingItem( 
			//                                                  aIdentifier, iItemData->iAccept );
			//            break;
			//
		default:
			break;
		}
	return settingItem;
	}

// ----------------------------------------------------------------------------
// CNormalSettingContainer::EditItemL(TInt aIndex, TBool aCalledFromMenu)
// Edit data
// ----------------------------------------------------------------------------
//    
void CNormalSettingContainer::EditItemL(TBool aCalledFromMenu)
	{
	TInt index = this->ListBox()->CurrentItemIndex();
	CAknSettingItemList::EditItemL(index, aCalledFromMenu);
	(*SettingItemArray())[index]->UpdateListBoxTextL();
	(*SettingItemArray())[index]->StoreL();
	}

void CNormalSettingContainer::EditItemL(TInt aIndex, TBool aCalledFromMenu)
	{
	CAknSettingItemList::EditItemL(aIndex, aCalledFromMenu);
	(*SettingItemArray())[aIndex]->UpdateListBoxTextL();
	(*SettingItemArray())[aIndex]->StoreL();
	}

// ----------------------------------------------------------------------------
// TKeyResponse CNormalSettingContainer::OfferKeyEventL()
// Handles the key events.
// ----------------------------------------------------------------------------
//
TKeyResponse CNormalSettingContainer::OfferKeyEventL(
		const TKeyEvent& aKeyEvent, TEventCode aType)
	{
	// No action if not key event
	if (aType != EEventKey)
		{
		return EKeyWasNotConsumed;
		}

	// The code of key event is checked
	switch (aKeyEvent.iCode)
		{
		// These events have no function in this application
		case EKeySpace:
		case EKeyRightArrow:
		case EKeyLeftArrow:
			break;
		default:
			CAknSettingItemList::OfferKeyEventL(aKeyEvent, aType);
			break;
		}
	return EKeyWasConsumed;
	}

// ----------------------------------------------------------------------------
// CNormalSettingContainer::SizeChanged()
// Called by framework when the view size is changed.
// ----------------------------------------------------------------------------
//
void CNormalSettingContainer::SizeChanged()
	{
	if (ListBox())
		{
		ListBox()->SetRect(Rect());
		}
	}

void CNormalSettingContainer::Init()
	{
	CQTextSetting* setting = (CQTextSetting*)CQInstance::GetByUid(CQInstance::ETextSettingInstance);
	iIap	= setting->GetAPNID();
	iBool1	= setting->GetBgColor();
	}

void CNormalSettingContainer::Save()
	{
	CQTextSetting* setting = (CQTextSetting*)CQInstance::GetByUid(CQInstance::ETextSettingInstance);
	TInt oldDisplay = setting->GetBgColor();
	setting->SetAPNID(iIap);
	setting->SetBgColor(iBool1);
	setting->SaveSetting();
	
	if (oldDisplay != iBool1)
		{
		SHEngine()->ReloadRSSBriefList();
		}
	}

// End of File
